package com.dnjn.mes.biz.websocket;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.dnjn.mes.biz.domain.MesWorkforceShift;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.util.List;

/**
 * 将JSON编码为entity
 */
public class MesWorkforceShiftEncoder implements Encoder.Text<Message> {

    /**
     * 发送编码 entity->json
     *
     * @param object
     * @return
     * @throws EncodeException
     */
    @Override
    public String encode(Message object) throws EncodeException {

        SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.put(Long.class, ToStringSerializer.instance);
        serializeConfig.put(Long.TYPE, ToStringSerializer.instance);
        //一定要设置SerializerFeature.PrettyFormat
        return JSONObject
                .toJSONString(object, serializeConfig);
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}

